package bTree.LeetCode;

import java.util.HashMap;
import java.util.Map;

public class 等价多米诺骨牌对的数量 {
    public int numEquivDominoPairs(int[][] dominoes) {
        int cnt=0;
        Map<String,Integer>map=new HashMap<>();
        for (int i=1;i<=9;i++){
            for(int j=1;j<=9;j++){
                map.put(String.valueOf(i)+","+String.valueOf(j), 0);
            }
        }
        for (int[] dominoe : dominoes) {
            int i = dominoe[0];
            int j = dominoe[1];
            if (i!=j){
                String s1 = String.valueOf(i) + "," + String.valueOf(j);
                String s2 = String.valueOf(j) + "," + String.valueOf(i);
                cnt+=map.get(s1);
                cnt+=map.get(s2);
                map.put(s1, map.get(s1)+1);
            }else {
                String s3 = String.valueOf(i) + "," + String.valueOf(j);
                cnt+=map.get(s3);
                map.put(s3, map.get(s3)+1);
            }

        }
        return cnt;
    }
}